package com.sxm.yiwei.adapters;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import android.widget.Toast;

import com.sxm.yiwei.R;

import java.util.HashMap;
import java.util.List;


/**
 * Created by KuKa on 2017/5/30.
 * 收货人
 */


public class SListViewSlideAdapter extends BaseAdapter {

    private List<HashMap<String,String>> bulbList;
    private Context context;
    private OnClickListenerEditOrDelete onClickListenerEditOrDelete;
    private String name;
    private String phone;
    private String address;
    private HashMap<String, String> sdata;
    private String houseNumber;

    public SListViewSlideAdapter(Context context){

        this.context=context;

    }

    public SListViewSlideAdapter(Context context, List<HashMap<String,String>> bulbList){
        this.bulbList=bulbList;
        this.context=context;}
    @Override
    public int getCount() {
        return bulbList.size();

    }
    @Override
    public Object getItem(int position) {
        return bulbList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        View view;
        ViewHolder viewHolder;
        if(null == convertView) {
            view = View.inflate(context, R.layout.sitem_slide_delete_edit, null);
            viewHolder=new ViewHolder();
            viewHolder.slinkPhone=(TextView)view.findViewById(R.id.servcer_linkphone);
            viewHolder.slinkName=(TextView)view.findViewById(R.id.servcer_linkname);
            viewHolder.slinkAddress = (TextView) view.findViewById(R.id.servcer_linkaddress);
            viewHolder.Delete=(TextView)view.findViewById(R.id.servcer_delete);
            viewHolder.Edit=(TextView)view.findViewById(R.id.servcer_Edit);
            view.setTag(viewHolder);//store up viewHolder

        }else {
            view=convertView;
            viewHolder=(ViewHolder)view.getTag();
        }
            sdata = bulbList.get(position);
            name = sdata.get("name");
            phone = sdata.get("phone");
            address = sdata.get("address");
        viewHolder.slinkAddress.setText(address+" ");
        viewHolder.slinkPhone.setText(phone);
        viewHolder.slinkName.setText(name);
        viewHolder.Delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onClickListenerEditOrDelete!=null){
                    onClickListenerEditOrDelete.OnClickListenerDelete(position);
                }
            }
        });
        viewHolder.Edit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onClickListenerEditOrDelete!=null){
                    onClickListenerEditOrDelete.OnClickListenerEdit(position);
                }
            }
        });

        notifyDataSetChanged();
        return view;
    }

    private class ViewHolder{
        TextView slinkAddress,Edit,Delete,slinkName,slinkPhone;

    }

    public interface OnClickListenerEditOrDelete{
        void OnClickListenerEdit(int position);
        void OnClickListenerDelete(int position);
    }

    public void setOnClickListenerEditOrDelete(OnClickListenerEditOrDelete onClickListenerEditOrDelete1){
        this.onClickListenerEditOrDelete=onClickListenerEditOrDelete1;
    }

}